//
//  CustomerDetailViewController.m
//  BaseProject
//
//  Created by 王洋 on 2020/7/10.
//  Copyright © 2020 王洋. All rights reserved.
//
#import "CustomerDetailHeaderView.h"
#import "CustomerDetailBottomView.h"

#import "CustomerDetailHistoryCell.h"

#import "AddMarkViewController.h"

#import "CustomerDetailViewController.h"

@interface CustomerDetailViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) CustomerDetailHeaderView *headerView;

@property (nonatomic, strong) CustomerDetailBottomView *bottomView;

@property (nonatomic, strong) UITableView *tableview;

@end

@implementation CustomerDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initView];
    
}

- (void)initView {
    
    self.title = @"客资详情";

    self.view.backgroundColor = UIColorHex(0xf1f1f1);
    
    [self.view addSubview:self.tableview];
    [self.view addSubview:self.bottomView];
    
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.mas_equalTo(0);
        make.height.mas_equalTo(50);
    }];
    
    [self.tableview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0);
        make.bottom.mas_equalTo(self.bottomView.mas_top);
    }];
    
    self.tableview.tableHeaderView = self.headerView;
    self.headerView.autoresizingMask = UIViewAutoresizingNone;
    
    [self.tableview reloadData];
}

- (void)addMark {
    AddMarkViewController *vc = [[AddMarkViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)changeStatus {

}

#pragma mark UITableviewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 85;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    CustomerDetailHistoryCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CustomerDetailHistoryCellID"];
    cell.selectionStyle =UITableViewCellSelectionStyleNone;
    
    return cell;
}

- (UITableView *)tableview {
    if (!_tableview) {
        _tableview = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableview.delegate = self;
        _tableview.dataSource = self;
        _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableview.backgroundColor =  UIColorHex(0xf1f1f1);
        
        _tableview.showsHorizontalScrollIndicator = NO;
        _tableview.showsVerticalScrollIndicator = NO;
        
        _tableview.estimatedSectionHeaderHeight = 0;
        _tableview.estimatedSectionFooterHeight = 0;
        _tableview.estimatedRowHeight = 0;
        
        [_tableview registerNib:[UINib nibWithNibName:@"CustomerDetailHistoryCell" bundle:nil] forCellReuseIdentifier:@"CustomerDetailHistoryCellID"];
        
    }
    return _tableview;
}

- (CustomerDetailHeaderView *)headerView {
    
    if (!_headerView) {
        _headerView = [[NSBundle mainBundle] loadNibNamed:@"CustomerDetailHeaderView"owner:nil options:nil].firstObject;
        _headerView.frame = CGRectMake(0, 0, TTScreenWidth, 466);

    }
    return _headerView;
}

- (CustomerDetailBottomView *)bottomView {
    
    if (!_bottomView) {
        _bottomView = [[NSBundle mainBundle] loadNibNamed:@"CustomerDetailBottomView"owner:nil options:nil].firstObject;
        _bottomView.frame = CGRectMake(0, 0, TTScreenWidth, 50);
        [_bottomView.addMarkBtn addTarget:self action:@selector(addMark) forControlEvents:UIControlEventTouchUpInside];
        [_bottomView.changeStatusBtn addTarget:self action:@selector(changeStatus) forControlEvents:UIControlEventTouchUpInside];
    }
    return _bottomView;
}

@end
